package com.example.gatewayserver.service;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

public class IpKeyResolver implements KeyResolver {
    /***
     * 根据IP限流
     * @param exchange
     * @return
     */
    public Mono<String> resolve(ServerWebExchange exchange) {
        String hostAddress = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
        String s = exchange.getRequest().getPath().toString();
        System.out.println("-----" + hostAddress + "-----" + s);
        return Mono.just(hostAddress);
    }
}
